import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int n;
		int[] a;
		int[] b;
		int i;
		int count = 0;
		Scanner cin = new Scanner(System.in);
		n = cin.nextInt();
		a = new int[n + 1];
		b = new int[n + 1];
		
		for (i = 1; i <= n; i++) {
			a[i] = cin.nextInt();
			b[i] = a[i] / 2;
		}

		do {
			for (i = n; i > 0; i--) {
				if (i - 1 == 0) {
					a[n] = b[i] + b[n];
					if (a[n] % 2 != 0) {
						count++;
						a[n]++;
					}
				} else {
					a[i - 1] = b[i] + b[i - 1];
					if (a[i - 1] % 2 != 0) {
						count++;
						a[i - 1]++;
					}
				}
			}
			for (i = 1; i <= n; i++)
				b[i] = a[i] / 2;
		} while (!isOver(a,n));
		
		System.out.println(count);
	}

	static boolean isOver(int a[],int n) {
		int x = a[1];
		for (int i = 1; i <= n; i++) {
			if (x != a[i])
				return false;
		}
		return true;
	}

}
